<?php 
set_time_limit(0);
ini_set("memory_limit", "12M");
if(!isset($_SESSION)) 
{ 
session_start(); 
} 
//sort id
function CompareIDASC($a, $b){
	if ($a[0] == $b[0]) {
		return 0;
	}
	return ($a[0] < $b[0]) ? -1 : 1;
}
function CompareIDDESC($a, $b){
	if ($a[0] == $b[0]) {
		return 0;
	}
	return ($a[0] > $b[0]) ? -1 : 1;
}
// sort name
function CompareNameASC($a, $b){
	if ($a[1] == $b[1]) {
		return 0;
	}
	return ($a[1] < $b[1]) ? -1 : 1;
}
function CompareNameDESC($a, $b){
	if ($a[1] == $b[1]) {
		return 0;
	}
	return ($a[1] > $b[1]) ? -1 : 1;
}
// sort count
function CompareCountASC($a, $b){
	if ($a[2] == $b[2]) {
		return 0;
	}
	return ($a[2] < $b[2]) ? -1 : 1;
}
function CompareCountDESC($a, $b){
	if ($a[2] == $b[2]) {
		return 0;
	}
	return ($a[2] > $b[2]) ? -1 : 1;
}
//sort Isreg
function CompareIsregASC($a, $b){
	if ($a[3] == $b[3]) {
		return 0;
	}
	return ($a[3] < $b[3]) ? -1 : 1;
}
function CompareIsregDESC($a, $b){
	if ($a[3] == $b[3]) {
		return 0;
	}
	return ($a[3] > $b[3]) ? -1 : 1;
}
//sort Noreg
function CompareNoregASC($a, $b){
	if ($a[4] == $b[4]) {
		return 0;
	}
	return ($a[4] < $b[4]) ? -1 : 1;
}
function CompareNoregDESC($a, $b){
	if ($a[4] == $b[4]) {
		return 0;
	}
	return ($a[4] > $b[4]) ? -1 : 1;
}
//sort Persent
function ComparePersentASC($a, $b){
	if ($a[5] == $b[5]) {
		return 0;
	}
	return ($a[5] < $b[5]) ? -1 : 1;
}
function ComparePersentDESC($a, $b){
	if ($a[5] == $b[5]) {
		return 0;
	}
	return ($a[5] > $b[5]) ? -1 : 1;
}
if (isset($_SESSION['s_cameras']) and is_array($_SESSION['s_cameras']) and isset($_REQUEST['flag'])) {
	
	$mylist = $_SESSION['s_cameras'];
	if($_REQUEST['flag']=='20'){
		usort($mylist, 'CompareIDASC');
	}elseif($_REQUEST['flag']=='21'){
		usort($mylist, 'CompareIDDESC');
	}
	elseif($_REQUEST['flag']=='30'){
		usort($mylist, 'CompareNameASC');
	}elseif($_REQUEST['flag']=='31'){
		usort($mylist, 'CompareNameDESC');
	}
	elseif($_REQUEST['flag']=='40'){
		usort($mylist, 'CompareCountASC');
	}elseif($_REQUEST['flag']=='41'){
		usort($mylist, 'CompareCountDESC');
	}	
	elseif($_REQUEST['flag']=='50'){
		usort($mylist, 'CompareIsregASC');
	}elseif($_REQUEST['flag']=='51'){
		usort($mylist, 'CompareIsregDESC');
	}	
	elseif($_REQUEST['flag']=='60'){
		usort($mylist, 'CompareNoregASC');
	}elseif($_REQUEST['flag']=='61'){
		usort($mylist, 'CompareNoregDESC');
	}	
	elseif($_REQUEST['flag']=='70'){
		usort($mylist, 'ComparePersentASC');
	}elseif($_REQUEST['flag']=='71'){
		usort($mylist, 'ComparePersentDESC');
	}	
	
	$_SESSION['s_cameras'] = $mylist;
	
	$index = 0;
	foreach ($mylist as $key =>$row){
			//array($row[id],$row[name],$counts,$isReg,$isNoReg,$percents,$m_fromdate,$m_todate,$monitorid);
			$index+=1;
			 ?>
			 <tr>
			 	<td width="6%"><?=$index?></td>
			 	<td width="6%"><?=$row[0]?></td>
			 	<td width="21%"><?=$row[1]?></td>
			 	<td width="11%"><?=$row[2]?></td>
			 	<td width="11%"><?=$row[3]?></td>
			 	<td width="11%"><?=$row[4]?></td>
			 	<td width="11%" <?php if($row[5] == 100){?>style="color:#00FFB6"<?php }elseif($row[5] < 50 ){?>style="color:#FF3A3A"<?php }?> ><?=$row[5]?>%</td>
			 	<td width="11%"  class="last" align="center"><a style="color: #0000FF;cursor: pointer" onclick="OpenView(this,'<?=$row[8]?>','<?=base64_encode($row[0])?>','<?=base64_encode($row[7])?>','<?=base64_encode($row[6])?>')">보기</a></td>
			 </tr>  
			 <?php 
			
				
	}  
	if ($index>0 and $index<$winH/28) {
	 	foreach(range(0,$winH/28-$index) as $i){
	 		?>
	 		<tr>
		 	<td width="6%">&nbsp;</td>
		 	<td width="6%">&nbsp;</td>
		 	<td width="21%">&nbsp;</td>
		 	<td width="11%">&nbsp;</td>
		 	<td width="11%">&nbsp;</td>
		 	<td width="11%">&nbsp;</td>
		 	<td width="11%">&nbsp;</td>
		 	<td width="11%"  class="last">&nbsp;</td>
		 	</tr>
	 	<?php }
	}
	  
}
?>

